import { IPSOne2OneDataDEField } from './ipsone2-one-data-defield';
import { PSFormulaDEFieldImpl } from './psformula-defield-impl';
import { IPSDERBase } from '../der/ipsderbase';

export class PSFormulaOne2OneDataDEFieldImpl extends PSFormulaDEFieldImpl implements IPSOne2OneDataDEField {
  protected psder: IPSDERBase | null = null;

  getPSDER(): IPSDERBase | null {
    if (this.psder != null) return this.psder;
    const value = this.M.getPSDER;
    if (value == null) {
      return null;
    }
    this.psder = this.getPSModel4('dataentity.der.IPSDERBase', value, 'getPSDER') as IPSDERBase;
    return this.psder;
  }

  get psDER(): IPSDERBase | null {
    return this.getPSDER();
  }

  getPSDERMust(): IPSDERBase {
    const value = this.getPSDER();
    if (value == null) {
      throw new Error('未指定一对一关系');
    }
    return value;
  }

  get cls(): string {
    return 'PSFormulaOne2OneDataDEFieldImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.defield.IPSOne2OneDataDEField') return true;
    return super.instanceof(cls);
  }
}
